package com.springapp.mvc.service.impl;

import com.springapp.mvc.dao.bean.Operation;
import com.springapp.mvc.dao.mapper.EXOperationMapper;
import com.springapp.mvc.service.Interface.OperationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by qinyy on 2018/7/15.
 */
@Service
public class OperationServiceImpl implements OperationService
{

    @Autowired(required = false)
    private EXOperationMapper mExOperationMapper;

    @Override
    public Operation getFirstUnexcutedOperation()
    {
        Operation operation = mExOperationMapper.selectFirstUnexcuted();
        return operation;
    }

    @Override
    public void changeOperationStatus(int OperationId, boolean excuted)
    {
        mExOperationMapper.changeOperationStatus(OperationId,excuted,System.currentTimeMillis());
    }

    @Override
    public void insertNewOperation(Operation operation)
    {
        operation.setCreatetime(System.currentTimeMillis());
        mExOperationMapper.insert(operation);
    }

    @Override
    public int getOperationCount()
    {
        return mExOperationMapper.getTotalNum();
    }

    @Override
    public List<Operation> queryOperationPaged(int limit,int offset,String sortPro,String sortType)
    {
        return mExOperationMapper.queryOperationPaged(limit,offset,sortPro,sortType);
    }

    @Override
    public int deleteOperation(int operationId)
    {
        return mExOperationMapper.deleteByPrimaryKey(operationId);
    }

    @Override
    public Operation queryOperationById(int operationId)
    {
        return mExOperationMapper.selectByPrimaryKey(operationId);
    }


}
